package exp.day03;

import java.awt.Point;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

//实现一个格点类（纵横坐标都是整数）
// 要求在[100X100]的网格内随机生成100个点，按照x坐标排序

class MyComp implements Comparator<Point> {
    //自定义排序
    @Override
    public int compare(Point o1, Point o2) {
        return o1.x - o2.x;     //按照x的升序
    }
}

public class P02Point {
    int x, y;

    P02Point() {
        this(0);
    }

    P02Point(int x) {
        this.x = x;
    }

    P02Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return String.format("%d,%d", x, y);
    }

    public static void main(String[] args) {
        Random ran = new Random();
        Point[] points = new Point[100];
        for (int i = 0; i < points.length; i++) {
            int x = ran.nextInt(100) + 1;
            int y = ran.nextInt(100) + 1;
            points[i] = new Point(x, y);
        }
//        Arrays.sort(points, new MyComp());
        Arrays.sort(points, (o1, o2) -> o1.x - o2.x);
        for (Point point : points) {
            System.out.println(point);
        }

    }
}
